//全屏
function fullScreen(){
    var el = document.documentElement;
    var rfs = el.requestFullScreen || el.webkitRequestFullScreen || el.mozRequestFullScreen || el.msRequestFullScreen;
    if (rfs) {
        rfs.call(el);
    }else if (typeof window.ActiveXObject !== "undefined") {
        var wscript = new ActiveXObject("WScript.Shell");
        if (wscript != null) {wscript.SendKeys("{F11}");}
    }
}
function exitScreen(){
    var el = document;
    var cfs = el.cancelFullScreen || el.webkitCancelFullScreen || el.mozCancelFullScreen || el.exitFullScreen;
    if (cfs) {cfs.call(el);
	}else if (typeof window.ActiveXObject !== "undefined") {
        var wscript = new ActiveXObject("WScript.Shell");
        if (wscript != null) {wscript.SendKeys("{F11}");}
    }
}
var iffull = 0;
fullscreen.onclick=function(){iffull++;iffull % 2 == 1 ? fullScreen():exitScreen();}
indent.onclick = function(){
	if (o('leftMain').className == 'off'){
		o('leftMain').class('');
		o('rightMain').class('');
		this.class('indent open');
		this.setAttribute('title','左侧缩进');
		this.html('<i class="ico">&#xe602;</i>');
	}else{
		o('leftMain').class('off');
		o('rightMain').class('off');
		this.class('indent close');
		this.setAttribute('title','左侧展开');
		this.html('<i class="ico">&#xe601;</i>');
	}
}

var totalw=tablist.offsetWidth;
zeai.listEach(zeai.tag(leftMain,'a'),function(obj){
	obj.onclick=function(){
		var a=this.innerHTML;
		title=a.replace('● ','');title=title.replace('＋ ','');
		title= title.replace(/<font.*?>.*?<\/font[^>]*>/ig,"");
		url  =obj.getAttribute("url");
		leftMain_clear_a_ed(obj);
		//
		tab_clear_ed();
		var tabedobj=tab_ifinurl(url);
		
		if(!zeai.empty(tabedobj)){
			tabedobj.class('ed');
			
			var W=get_W();
			if(W>=totalw){
				var tabedobj_l = tabedobj.offsetLeft;
				var tabedobj_w = tabedobj.offsetWidth;
				if(tabedobj_l < totalw){
					tablist_box.css('left:0;');
				}else if(tabedobj_l>totalw){
					tablist_box.css('transform:translateX('+(tabedobj_w-totalw)+'px)');
				}
			}
			
		}else{
			var li=zeai.addtag('li');li.class('ed');li.html('<span>'+title+'</span>');li.setAttribute('url',url);
			li.onclick=function(){tab_a(this);}
			var i=zeai.addtag('i');i.class('ico');i.html('&#xe606;');
			var em=zeai.addtag('em');em.append(i);
			em.onclick=function(e){
				e.stopPropagation();
				var emp=em.parentNode;
				var emp_w=emp.offsetWidth,emp_l=emp.offsetLeft;
				var actobj=emp.previousElementSibling;
				emp.parentNode.removeChild(emp);
				//激活前一个tab li
				if(typeof(actobj)=='object'){
					tab_clear_ed();
					var acturl = actobj.getAttribute("url");
					actobj.class('ed');iframe.src=acturl;
					//定位leftMain a
					var leftMainedobj=leftMain_ifinurl(acturl);
					if(typeof(leftMainedobj) == 'object')leftMain_clear_a_ed(leftMainedobj);
				}
				//滑动tab li
				var W=get_W();
				if(W>=totalw){
					var boxL=tablist_box.style.left;
					boxL = parseInt(boxL.replace('px',''));
					boxL = -(boxL+emp_l);
					tablist_box.css('left:'+boxL+'px');
				}else{
					tablist_box.css('left:0');
				}
			}
			li.append(em);tablist_box.append(li);
			setTimeout(function(){tab_next.click();},200);
		}
		iframe.src=url;
	}
});
function get_W(){var w=0;zeai.listEach(zeai.tag(tablist_box,'li'),function(obj){w=w+obj.offsetWidth;});return w;}
function leftMain_clear_a_ed(ed){
	zeai.listEach(zeai.tag(leftMain,'a'),function(obj){
		if(obj.hasClass('ed'))obj.removeClass('ed');
	});
	ed.class('ed');
}
function tab_clear_ed(){
	zeai.listEach(zeai.tag(tablist,'li'),function(obj){
		if(obj.hasClass('ed'))obj.removeClass('ed');
	});
}
function tab_a(that){
	tab_clear_ed();
	var url = that.getAttribute("url");
	if(!that.hasClass('ed'))that.class('ed');
	iframe.src=url;
	//处理左侧同步选中
	var leftMainedobj=leftMain_ifinurl(url);
	if(typeof(leftMainedobj) == 'object')leftMain_clear_a_ed(leftMainedobj);
}
function leftMain_ifinurl(url){
	var obj2='';
	zeai.listEach(zeai.tag(leftMain,'a'),function(obj){
		var url2 =obj.getAttribute("url");
		if(url==url2){
			obj2 = obj;	
		}
	});
	return obj2;
}
function tab_ifinurl(url){
	var obj2='';
	zeai.listEach(zeai.tag(tablist,'li'),function(obj){
		var url2 =obj.getAttribute("url");
		if(url==url2){
			obj2 = obj;	
		}
	});
	return obj2;
}
tablist_index.onclick=function(){
	tab_a(this);
	if(!this.hasClass('ed'))this.class('ed');
}
tab_back.onclick=function(){
	//tablist.scrollLeft=0;模式1
	tablist_box.css('left:0');
}
tab_next.onclick=function(){
	var W=get_W();
	if(W>=totalw){
		var movew=W-totalw;
		tablist_box.css('left:-'+movew+'px');
	}
}
tab_menu.onmouseover=function(){
	toptabmenubox.show();
}
toptabmenubox.onmouseover=function(){
	toptabmenubox.show();
}
toptabmenubox.onmouseout=function(){
	toptabmenubox.hide();
}
toptabmenubox.children[0].onclick=function(){
	var listobj=zeai.tag(tablist_box,'li');
	var L=listobj.length;
	var objarr=[];
	for(var k=1;k<L;k++) {
		if(listobj[k].className!='ed')objarr.push(listobj[k]);
	}
	zeai.listEach(objarr,function(obj){
		obj.parentNode.removeChild(obj);
		listobj[0].class('');
	});
}
toptabmenubox.children[1].onclick=function(){
	var listobj=zeai.tag(tablist_box,'li');
	var L=listobj.length-1;
	var objarr=[];
	for(var k=L;k>0;k--) {
		if(listobj[k].className=='ed')break;
		objarr.push(listobj[k]);
	}
	zeai.listEach(objarr,function(obj){
		obj.parentNode.removeChild(obj);
		listobj[0].class('');
	});
}
toptabmenubox.children[2].onclick=function(){
	var listobj=zeai.tag(tablist_box,'li');
	var L=listobj.length;
	var objarr=[];
	for(var k=1;k<L;k++) {
		if(listobj[k].className=='ed')break;
		objarr.push(listobj[k]);
	}
	zeai.listEach(objarr,function(obj){
		obj.parentNode.removeChild(obj);
		listobj[0].class('');
	});
}
toptabmenubox.children[3].onclick=function(){
	var listobj=zeai.tag(tablist_box,'li');
	var L=listobj.length;
	var objarr=[];
	for(var k=1;k<L;k++) {objarr.push(listobj[k]);}
	zeai.listEach(objarr,function(obj){
		obj.parentNode.removeChild(obj);
	});
	listobj[0].class('ed');
	iframe.src=listobj[0].getAttribute("url");
}